

public class Data {

	//create a singelton - This is a global variable 
	private static final Data Instance = new Data();
	
	// a private constructor
	private Data(){
		
	}
	
	
	public static Data getInstance() {
		return Instance;
	}


	//initialize the matrix 
	public void initialize(int m[][]){
		//go over the the chromosoms
		for(int i=0; i<m.length; i++){
			for(int j=0; j<m[i].length; j++){
				m[i][j]=1;
			}
		}
	}
	//end of the initialization
	
	
	
	
	/*
	 * the function get array with history of 3 last choices
	 * and array that represent a chromosom, and according to the
	 * history he choice a index in the chromosom, that mean 0 or 1 
	 *  0=cooperate , 1=defect
	 */
	 public int choice(int his[], int chrom[]){
		 
		//the index in the chromosom 
	    int index = 0;
		int j = 5;
	    //run over the chromosom
	    for(int i=0; i<6; i++){
	    	index = index + ( his[j]*powerTwo(i) );
	    	j--;
	    }
	    
		return chrom[index];				 
	 }
	//end of choice	
	
	
	 public int powerTwo(int power){
		 int tmp = 2;

		 if(power==0){
			 return 1;
		 }
		 else if(power>0){
			 for(int i=1; i<power; i++){
				 tmp = tmp*2; 
			 }
			 return tmp;
		 }//end of else
		 else{
			 return -1;
		 }
	 }
	 
	 
	 /*
	  * get array with a score of the chromosoms, index of two 
	  * chromosoms and their decisions and update their score 
	  */
	 public void score(int score[], int ch1, int ch2, int choice1, int choice2){
		 
		 //chromo1 Cooperate
		 if(choice1==0){
			//chromo2 Cooperate
			 if(choice2==0){
				 score[ch1] = score[ch1] + 3;
				 score[ch2] = score[ch2] + 3;
			 }
			//chromo2 Defect
			 else{
				  score[ch2] = score[ch2] + 5;			 				 
			 }
		 }
		//chromo1 Defect
		 else{
			//chromo2 Cooperate
			 if(choice2==0){
				 score[ch1] = score[ch1] + 5;	
			 }
			//chromo2 Defect
			 else{
				 score[ch1] = score[ch1] + 1;
				 score[ch2] = score[ch2] + 1;
			 }
		 }
	 }
	 
	 
	 
	/*public int choice(int his[], int chrom[]){
		
		if(his[0]==0){
			if(his[1]==0){
				if(his[2]==0){
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								//it is the first choice -   CC CC CC
									return chrom[0];
								}
							//in case his[5]=1
							else{				
								return chrom[1];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[2];
							}
							//in case his[5]=1
							else{
								return chrom[3];
							}
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[4];
							}
							//in case his[5]=1
							else{
								return chrom[5];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[6];
							}
							//in case his[5]=1
							else{
								return chrom[7];
							}													
						}
						
					}
				}
				//in case his[2]=1
				else{
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								return chrom[8];
							}
							//in case his[5]=1
							else{
								return chrom[9];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[10];
							}
							//in case his[5]=1
							else{
								return chrom[11];
							}							
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[12];
							}
							//in case his[5]=1
							else{
								return chrom[13];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[14];
							}
							//in case his[5]=1
							else{
								return chrom[15];
							}							
						}						
					}
					
				}
				
			}//end if his[1]==0
			
			//in case his[1]=1
			else{
				if(his[2]==0){
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								//it is the first choice -   CC CC CC
									return chrom[16];
								}
							//in case his[5]=1
							else{				
								return chrom[17];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[18];
							}
							//in case his[5]=1
							else{
								return chrom[19];
							}
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[20];
							}
							//in case his[5]=1
							else{
								return chrom[21];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[22];
							}
							//in case his[5]=1
							else{
								return chrom[23];
							}													
						}
						
					}
				}
				//in case his[2]=1
				else{
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								return chrom[24];
							}
							//in case his[5]=1
							else{
								return chrom[25];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[26];
							}
							//in case his[5]=1
							else{
								return chrom[27];
							}							
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[28];
							}
							//in case his[5]=1
							else{
								return chrom[29];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[30];
							}
							//in case his[5]=1
							else{
								return chrom[31];
							}							
						}						
					}
					
				}
								
			}
		}
		//end of the first if - his[0]=0
		

		//in case his[0]=1
		else{
			if(his[1]==0){
				if(his[2]==0){
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								//it is the first choice -   CC CC CC
									return chrom[32];
								}
							//in case his[5]=1
							else{				
								return chrom[33];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[34];
							}
							//in case his[5]=1
							else{
								return chrom[35];
							}
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[36];
							}
							//in case his[5]=1
							else{
								return chrom[37];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[38];
							}
							//in case his[5]=1
							else{
								return chrom[39];
							}													
						}
						
					}
				}
				//in case his[2]=1
				else{
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								return chrom[40];
							}
							//in case his[5]=1
							else{
								return chrom[41];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[42];
							}
							//in case his[5]=1
							else{
								return chrom[43];
							}							
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[44];
							}
							//in case his[5]=1
							else{
								return chrom[45];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[46];
							}
							//in case his[5]=1
							else{
								return chrom[47];
							}							
						}						
					}
					
				}
				
			}//end if his[1]==0
			
			//in case his[1]=1
			else{
				if(his[2]==0){
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								//it is the first choice -   CC CC CC
									return chrom[48];
								}
							//in case his[5]=1
							else{				
								return chrom[49];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[50];
							}
							//in case his[5]=1
							else{
								return chrom[51];
							}
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[52];
							}
							//in case his[5]=1
							else{
								return chrom[53];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[54];
							}
							//in case his[5]=1
							else{
								return chrom[55];
							}													
						}
						
					}
				}
				//in case his[2]=1
				else{
					if(his[3]==0){
						if(his[4]==0){
							if(his[5]==0){
								return chrom[56];
							}
							//in case his[5]=1
							else{
								return chrom[57];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[58];
							}
							//in case his[5]=1
							else{
								return chrom[59];
							}							
						}
					}
					//in case his[3]=1
					else{
						if(his[4]==0){
							if(his[5]==0){
								return chrom[60];
							}
							//in case his[5]=1
							else{
								return chrom[61];
							}
						}
						//in case his[4]=1
						else{
							if(his[5]==0){
								return chrom[62];
							}
							//in case his[5]=1
							else{
								return chrom[63];
							}							
						}						
					}
					
				}
								
			}			
		}
		
	}
	//end of choice
	*/
}
